//
//  NextAttentionViewController.m
//  LoveAttention
//
//  Created by 鞠超 on 15/12/30.
//  Copyright © 2015年 JC. All rights reserved.
//

#import "NextAttentionViewController.h"

#import "DataProvider.h"
#import "UIImageView+WebCache.h"
#import "SVProgressHUD.h"
#import "Invite_Model.h"
@interface NextAttentionViewController ()

@property (nonatomic, strong) UIImageView * image;

@property (nonatomic, strong) UILabel * name;

@property (nonatomic, strong) UILabel * name_nicheng;

@property (nonatomic, strong) UILabel * sex;

@property (nonatomic, strong) UILabel * date;

@property (nonatomic, strong) UILabel * address;

@end

@implementation NextAttentionViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navigationController];
    
    [self p_setupView];
    
    [self p_data];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - navigationController
- (void)p_navigationController
{
    self.view.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    self.navigationItem.title = @"资料详情";
    UIButton * btn = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [btn setBackgroundImage:[UIImage imageNamed:@"返回"] forState:(UIControlStateNormal)];
        btn.frame = CGRectMake(10, 20, 25, 30);
    [btn addTarget:self action:@selector(leftBarButtonItemAction:) forControlEvents:(UIControlEventTouchUpInside)];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    self.navigationItem.leftBarButtonItem.tintColor = [UIColor blackColor];
}
//点击事件(左)
- (void)leftBarButtonItemAction:(UIBarButtonItem *)bar
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - 布局
- (void)p_setupView
{
    UIImageView * view_bg = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, 120)];
    view_bg.image = [UIImage imageNamed:@"头像背景"];
    [self.view addSubview:view_bg];
    
    self.image = [[UIImageView alloc] initWithFrame:CGRectMake(25, 30, 60, 60)];
//    self.image.backgroundColor = [UIColor cyanColor];
    self.image.layer.cornerRadius = 30;
    self.image.image = [UIImage imageNamed:@"头像"];
    [view_bg addSubview:self.image];
    
    self.name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image.frame) + 25, CGRectGetMidY(self.image.frame)  - 20, 200, 40)];
    self.name.text = @"爱关注";
    self.name.font = [UIFont systemFontOfSize:20];
    self.name.textColor = [UIColor whiteColor];
    [view_bg addSubview:self.name];
    
    UIView * view_bottom = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(view_bg.frame), self.view.frame.size.width, 180)];
    view_bottom.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view_bottom];
    
    //昵称
    UILabel * label_1 = [[UILabel alloc] initWithFrame:CGRectMake(35, 10, 50, 30)];
    label_1.text = @"昵称";
    label_1.font = [UIFont systemFontOfSize:14];
    label_1.textColor = [UIColor grayColor];
    [view_bottom addSubview:label_1];
    
    self.name_nicheng = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_1.frame) + 35, 10, 180, 30)];
    self.name_nicheng.font = [UIFont systemFontOfSize:14];
    self.name_nicheng.text = @"哈哈";
    [view_bottom addSubview:self.name_nicheng];
    
    UIView * view_1 = [[UIView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.name_nicheng.frame) + 5, self.view.frame.size.width - 40, 1)];
    view_1.backgroundColor = [UIColor grayColor];
    [view_bottom addSubview:view_1];
    
    //性别
    UILabel * label_2 = [[UILabel alloc] initWithFrame:CGRectMake(35, CGRectGetMaxY(view_1.frame) + 10, 50, 30)];
    label_2.text = @"性别";
    label_2.font = [UIFont systemFontOfSize:14];
    label_2.textColor = [UIColor grayColor];
    [view_bottom addSubview:label_2];
    
    self.sex = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_2.frame) + 35, CGRectGetMaxY(view_1.frame) + 10, 180, 30)];
    self.sex.font = [UIFont systemFontOfSize:14];
    self.sex.text = @"未设置";
    [view_bottom addSubview:self.sex];
    
    UIView * view_2 = [[UIView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.sex.frame) + 5, self.view.frame.size.width - 40, 1)];
    view_2.backgroundColor = [UIColor grayColor];
    [view_bottom addSubview:view_2];
    
    //出生日期
    UILabel * label_3 = [[UILabel alloc] initWithFrame:CGRectMake(35, CGRectGetMaxY(view_2.frame) + 10, 60, 30)];
    label_3.text = @"出生日期";
    label_3.font = [UIFont systemFontOfSize:14];
    label_3.textColor = [UIColor grayColor];
    [view_bottom addSubview:label_3];
    
    self.date = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_3.frame) + 25, CGRectGetMaxY(view_2.frame) + 10, 180, 30)];
    self.date.font = [UIFont systemFontOfSize:14];
    self.date.text = @"未设置";
    [view_bottom addSubview:self.date];
    
    UIView * view_3 = [[UIView alloc] initWithFrame:CGRectMake(20, CGRectGetMaxY(self.date.frame) + 5, self.view.frame.size.width - 40, 1)];
    view_3.backgroundColor = [UIColor grayColor];
    [view_bottom addSubview:view_3];
    
    //地址
    UILabel * label_4 = [[UILabel alloc] initWithFrame:CGRectMake(35, CGRectGetMaxY(view_3.frame) + 10, 50, 30)];
    label_4.text = @"地址";
    label_4.font = [UIFont systemFontOfSize:14];
    label_4.textColor = [UIColor grayColor];
    [view_bottom addSubview:label_4];
    
    self.address = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(label_4.frame) + 35, CGRectGetMaxY(view_3.frame) + 10, 180, 30)];
    self.address.font = [UIFont systemFontOfSize:14];
    self.address.text = @"未设置";
    [view_bottom addSubview:self.address];
    

}

#pragma mark - 数据
- (void)p_data
{
    DataProvider * dataprovider = [[DataProvider alloc] init];
    
    [dataprovider setDelegateObject:self setBackFunctionName:@"UserDetail:"];
    [dataprovider UserDetailWith:self.userid];
    
    
}

- (void)UserDetail:(id )dict
{
    NSLog(@"%@",dict);
    
    if ([dict[@"status"][@"succeed"] intValue] == 1) {
        @try
        {
            Invite_Model * model = [[Invite_Model alloc] init];
            
            [model setValuesForKeysWithDictionary:dict[@"data"]];
            
            if([model.name length] == 0)
            {
                self.name.text = @"未设置";
                self.name_nicheng.text = @"未设置";
            }
            else
            {
                self.name.text = [NSString stringWithFormat:@"%@",model.name];
                self.name_nicheng.text = [NSString stringWithFormat:@"%@",model.name];
            }
            
            self.image.layer.masksToBounds = YES;
            NSString *url = [NSString stringWithFormat:@"http://115.28.67.86:8080/aigz/upload/%@",model.headportain];
            [self.image sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"头像"]];
            
            if([model.sex length] == 0)
            {
                self.sex.text = @"未设置";
            }
            else
            {
                 self.sex.text = [NSString stringWithFormat:@"%@",model.sex];
            }
       
            if([model.birthday length] == 0)
            {
                self.date.text = @"未设置";
            }
            else
            {
                self.date.text = [NSString stringWithFormat:@"%@",model.birthday];
            }
            
            if([model.address length] == 0)
            {
                self.address.text = @"未设置";
            }
            else
            {
                self.address.text = [NSString stringWithFormat:@"%@",model.address];
            }
            
        }
        @catch (NSException *exception) {
            
        }
        @finally {
            
        }
    }
    else
    {
        [SVProgressHUD showErrorWithStatus:dict[@"status"][@"errdesc"] maskType:SVProgressHUDMaskTypeBlack];
    }
}





@end
